/*
*	create by  jack ,20210705
*
*	描述 ：
*		  该文件提供了一套设备调用的接口，屏蔽具体实现细节,以达到应用程序可以在不同的平台上联合调试。
*		  open 返回该设备枚举类别。无设备实现时，返回负数.
*   修改记录：[内容][作者][时间]
*
*/


#ifndef _SANJI_OS_RCC_ABP_H_
#define _SANJI_OS_RCC_ABP_H_

#include "define_comm.h"

#include "stm32f1xx_hal.h"
#include "stm32f1xx.h"

//rtc
struct rtc_date
{
  sj_uint8 weekDay;
  sj_uint8 month;
  sj_uint8 date;
  sj_uint8 year;
};

struct rtc_time
{
  sj_uint8 hours;
  sj_uint8 minutes;
  sj_uint8 seconds;
};

struct peripheral_rtc
{
    sj_uint32 *instance;
    sj_uint32 asynchPrediv;
    sj_uint32 output;
};

struct rcc_lse_periph
{
    sj_char apb_offset;
    sj_uint32 periph_clock_selection;
    sj_uint32 rtc_cloc_selection;
    sj_uint32 oscillator_type;
    sj_uint32 lse_state;
};


struct peripheral_nvic
{
    sj_char irq_num;
    sj_char preempt_priority;
    sj_char sub_priority;
};


struct rcc_apb_periph
{
    sj_char apb;
    sj_char apb_offset;
};


struct peripheral_timer
{
    sj_uint32 base;
    sj_int8   prescaler;
    sj_int8   period;
    sj_int8   mode;
    sj_int8   division;
    sj_int8   id;
};

struct peripheral_usart
{
    sj_uint32 base;
    sj_int32 bound;
    sj_int8 world_len;
    sj_int8 stop_n;
    sj_int8 parity;
    sj_int8 mode;
    sj_int8 id;
    sj_char* rx_buf;
    sj_int32 rx_bufsize;
};

//adc
struct rcc_adc_periph_clk
{
    sj_uint32 periph_clock_selection;
    sj_uint32 adc_clock_selection;
};

struct peripheral_adc
{
    sj_uint32 base;
    sj_uint32 scanconv_mode;
    sj_uint32 continuousconv_mode;
    sj_uint32 discontinuousconv_mode;
    sj_uint32 external_trigconv;
    sj_uint32 data_align;
    sj_uint32 nbrofconversion;
};

struct peripheral_adc_channel
{
    sj_uint32 channel;
    sj_uint32 rank;
    sj_uint32 samplingTime;
};


sj_void periph_clock_config(struct rcc_apb_periph *apb);


sj_void peripheral_timer_init(struct peripheral_timer *timer);


sj_void peripheral_usart_init(struct peripheral_usart *usart);


sj_void peripheral_nvic_init(struct peripheral_nvic *nvic);
//rtc
sj_void peripheral_rtc_init(struct peripheral_rtc *hrtc);

sj_void peripheral_rtc_clock_config(struct rcc_lse_periph *rtc_lse);

sj_void peripheral_rtc_get_time(struct rtc_date *data,struct rtc_time *time);
//adc
sj_void peripheral_adc_clock_config(struct rcc_adc_periph_clk *adc_clk);

sj_void peripheral_adc_init(struct peripheral_adc *hadc, struct peripheral_adc_channel *hadc_channel);

sj_uint16 peripheral_adc_start_get_data(struct peripheral_adc *hadc);

#endif
